<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2021-3-6
  Time: 10:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--要想使用jstl core，要引入这行--%>
<%--https://www.runoob.com/jsp/jsp-jstl.html--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--使用jstl时maven需要两个dependency，同时在tomcat/lib下把两个jar包复制过去--%>
<html>
<head>
    <title>Title</title>
</head>
<body>

<%--自提交--%>
<form action="jstl.jsp" method="get">
    <label>
        <input type="text" name="name" value="${param.name}">
    </label>
    <input type="submit">
</form>
<%--test中是bool表达式 var则是其值--%>
<c:if test="${param.name=='admin'}" var="admin">
    <c:out value="welcome"/> <%--输出value--%>
</c:if>
<c:out value="${admin}"/>
<%--如果标签里面没嵌套标签，要用/>结尾，否则加一个</c...>--%>


<c:set value="8" var="score"/>
<%--相当于if; else if...--%>
<c:choose>
    <c:when test="${score>=90}">
        优秀
    </c:when>
    <c:when test="${score>=80}">
        还行
    </c:when>
    <c:when test="${score>=70}">
        一般
    </c:when>
    <c:when test="${score<70}">
        菜
    </c:when>
</c:choose>

<%
    ArrayList<String> people = new ArrayList<>();
    people.add("张三");
    people.add("李四");
    people.add("王五");
    people.add("张三");
    people.add("李四");
    people.add("王五");

    request.setAttribute("list", people);
%>
<%--遍历list,其中var值是每一次遍历的元素值相当于 for(people : list)   begin是起始下标,end为结束下标,step是步长
当然后面三个参数可不用
--%>
<c:forEach var="people" items="${list}" begin="0" end="5" step="1">
    <c:out value="${people}"/> <br/>
</c:forEach>
</body>
</html>
